package com.codingfuture.web.controller;

import com.codingfuture.entity.CourseContent;
import com.codingfuture.service.CourseContentService;
import com.codingfuture.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CourseContentController {
    @Autowired
    private CourseContentService courseContentService;

    @GetMapping("/course/contents/{id}")
    public Result list(@PathVariable Integer id) {
        List<CourseContent> list = courseContentService.list(id);
        return Result.ok(list);
    }

    @PostMapping("/course/content")
    public Result add(CourseContent courseContent) {
        int i = courseContentService.add(courseContent);
        if (i > 0) {
            return Result.ok();
        } else {
            return Result.err();
        }
    }
}
